import React, { Component } from 'react'

export default class App extends Component {
  testRef = React.createRef()
  state = { name: '1111'}
  render() {
    return (
      <div>
        {/* 非受控组件中才设置 defaultValue */}
        <input type="text" onChange={(event) => {
          this.setState({
            name: event.target.value
          })
        }} defaultValue="2222" value = { this.state.name }/>
        <input type="text" ref={ this.testRef } defaultValue = "你好"/>
        <button onClick = { 
          () => {
            console.log(this.testRef.current.value)
          }
        }>获取</button>
      </div>
    )
  }
}
